package com.thinkfit.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.common.lib.bean.DeviceInfoBean;
import com.common.lib.bean.VideoListBean;
import com.thinkfit.jy.R;

import org.jetbrains.annotations.NotNull;

public class ProceduralTrainingAdapter extends BaseQuickAdapter<VideoListBean, BaseViewHolder> {

    private Context mContext;
    private int[] colors;

    public ProceduralTrainingAdapter(Context context) {
        super(R.layout.item_procedural_training);
        mContext = context;
    }


    @Override
    protected void convert(@NotNull BaseViewHolder helper, VideoListBean bean) {
        colors = new int[]{mContext.getResources().getColor(R.color.color_45B4FF),
                mContext.getResources().getColor(R.color.color_36D16F),
                mContext.getResources().getColor(R.color.color_FFBB00),
                mContext.getResources().getColor(R.color.color_FF8A05),
                mContext.getResources().getColor(R.color.color_FF5959),
                mContext.getResources().getColor(R.color.color_AA51F0)};
        LinearLayout llChart = helper.getView(R.id.ll_chart);
        for (DeviceInfoBean deviceInfoBean : bean.getBrustlist()){
//            items.add((float) deviceInfoBean.getDrap());
            setView(llChart,deviceInfoBean);
        }
        helper.setText(R.id.tv_drill,bean.getName());
        helper.setText(R.id.tv_use_up,bean.getKcal()+"Kcl");
        helper.setText(R.id.tv_time,bean.getMin()+mContext.getResources().getString(R.string.app_minutes));



//        initBiao(chart,maxY);
//        setBarChartData(chart,items,"",mContext.getResources().getColor(R.color.color_2E2E2E));
//
//        initBiao(chart1,maxY);
//        setBarChartData(chart1,itemsX,"",
//                mContext.getResources().getColor(R.color.color_45B4FF),
//                mContext.getResources().getColor(R.color.color_36D16F),
//                mContext.getResources().getColor(R.color.color_FFBB00),
//                mContext.getResources().getColor(R.color.color_FF8A05),
//                mContext.getResources().getColor(R.color.color_FF5E5E),
//                mContext.getResources().getColor(R.color.color_AA51F0));
    }

    public void setView(LinearLayout llChart,DeviceInfoBean deviceInfoBean){
        ViewGroup.LayoutParams layoutParams = llChart.getLayoutParams();
        int maxHight = layoutParams.height;
        int maxWidth = layoutParams.width;
        View item = LayoutInflater.from(mContext).inflate(R.layout.item_histogram, null);
        View v1 = item.findViewById(R.id.v1);
        View v2 = item.findViewById(R.id.v2);

        ViewGroup.LayoutParams layoutParams1 = v1.getLayoutParams();

        layoutParams1.height = Math.round(maxHight*deviceInfoBean.getHeight());
        layoutParams1.width = Math.round(maxWidth*deviceInfoBean.getWidth());
        v1.setLayoutParams(layoutParams1);

        v2.setBackgroundColor(setColor(deviceInfoBean.getWatt()));

        llChart.addView(item);
    }

    public int setColor(int wait){
        if(wait<60){
            return colors[0];
        }else if(60<=wait && wait<=80){
            return colors[1];
        }else if(80<wait && wait<100){
            return colors[2];
        }else if(100<=wait && wait <110){
            return colors[3];
        }else if(110<=wait && wait <=120){
            return colors[4];
        }else {
            return colors[5];
        }

    }

}
